/**
 * 十一选五页面部分方法
 */
// 倒计时准备
var running_time = 0;
// 用户投注记录(最多有三个投注组)
var oddsArr    = new Array();
//定位用户的玩法
var user_play  = 'default';
var betting    = {};
betting[user_play]    = {
		'one'   : new Array(),
		'two'   : new Array(),
		'three' : new Array(),
};
var clear_kj_ready = '';
function load_init(){
	$('.tag_lottery_title').html(resData.lotteryInfo.title);
	$('.tag_lottery_icon_style').addClass(resData.lottCateInfo.tags);
	$('.tag_lott_shangqi').html(resData.shangqi.period);
	// 当前期号的倒计时
	var now_timestamp  = (Date.parse(new Date()) / 1000) * 1; // js的时间戳会带毫秒
	// 载入同种类型的彩种
	lottery_list();
	// 检查上期是否有开奖
	if(resData.shangqi.code){
		clear_kj_ready = setTimeout('shangqi_kaijiang("' + resData.shangqi.code + '")', 2000);
	}
	
	// 如果当前没有期号，做一个提示
	if(!$.isEmptyObject(resData.lotting)){
		$('.tag_lott_lotting').html(resData.lotting.period);
		$('.tag_lott_next').html(resData.nextbet.period);
		// 当前期号结束时间减掉当前时间戳为剩下时间
		running_time = resData.lotting.stoptime - resData.ftime;
		daojishi();
	}else{
		$('.tag_lott_lotting').html('----');
		$('#tag_runningtime').html('暂未开始！');
	}
}

/**
 * =========================================================================
 * 上期开奖结果，这里主要是js效果以及控制
 */
function shangqi_kaijiang(code_str){
	// 设置上期开奖内容
	var kaijiang_Str  = '';
	var award_numbers = code_str.split(',');
	for(var i = 0; i < award_numbers.length; i++){
		kaijiang_Str += '<li>' + award_numbers[i] + '</li>';
	}
	$('.tag_Award_Number').html(kaijiang_Str);
}

/**
 * =========================================================================
 * 倒计时计算，返回00:00:00形式倒计时
 * @param second
 */
function daojishi (){
	var hour   = '00';
	var minute = '00';
	var second = '00';
	if (running_time <= 0){
		$('.tag_runningtime').html(hour + ':' + minute + ':' + second);
		// 当前期号结束，获取下批期号信息， 并重新载入数据.
		var content_msg  = resData.shangqi.period + '期已截止<br/>';
			content_msg += '当前期号<font style="color: red;">' + $('.tag_lott_next').html() + '</font><br/>';
			content_msg += '投注时请注意期号';
		layer_msg('温馨提示', content_msg, '');
		setTimeout("re_init()", 1000);
		return;
	}
	hour       = parseInt(running_time / (60 * 60));
	minute     = parseInt(running_time / (60));
	second     = parseInt(running_time % (60));
	if(hour == 0){
		hour = '00';
	}else if(hour > 0 && hour < 10){
		hour = '0' + hour;
	}
	if(minute == 0){
		minute = '00';
	}else if(minute > 0 && minute < 10){
		minute = '0' + minute;
	}
	if(second == 0){
		second = '00';
	}else if (second > 0 && second < 10){
		second = '0' + second;
	}
	$('.tag_runningtime').html(hour + ':' + minute + ':' + second);
	running_time--;
	setTimeout("daojishi()", 1000);
}

/**
 * 同种类型的彩种列表
 */
function lottery_list(){
	var str = '';
	$.each(resData.lotteryList, function (index, value){
		if(value.id == resData.lotteryInfo.id){
			str += '<li class="active tag_lottery_item" ami="' + value.id +'">' + value.title + '</li>';
		}else{
			str += '<li class="tag_lottery_item" ami="' + value.id +'">' + value.title + '</li>';
		}
	})
	$('.tag_lottery_list').html(str);
}

/**
 * 获取玩法
 * @param m: main_play[主玩法] == 页面载入一次
 * @param f: follow_play[从玩法]
 */
var play_main   = '';
var play_follow = '';
function get_main_play_mode(m){
	if(play_main.main_name == m){
		// 重复点击
		return;
	}
	if(m ==''){
		// 未指定玩法载入默认第一种玩法
		$.each(resData.playItem.mainItem, function (index, value){
			value.main_name = index;
			play_main       = value;
			return false;
		})
	}else{
		$.each(resData.playItem.mainItem, function (index, value){
			if(m == index){
				value.main_name = index;
				play_main       = value;
				return false;
			}
		})
	}
	$('.tag_lott_play_main_name').html(play_main.play_name);
	// 展示从玩法信息
	$('.tag_lott_play_follow').html(function (){
		// 默认载入第一个玩法
		var follow_str = '';
		$.each(play_main.play, function(index, value){
			if(follow_str){
				follow_str += '<a href="javascript:void(0);"  href="javascript:void(0);"  class="tag_follow_play_item" ami="' + index + '">' + value.name + '</a>';
			}else{
				follow_str += '<a href="javascript:void(0);"  href="javascript:void(0);"  class="tag_follow_play_item curr" ami="' + index + '">' + value.name + '</a>';
			}
		});
		return follow_str;
	});
}

function get_follow_play_mode(f, reload=true){
	if(play_follow.follow_name == f && reload != true){
		// 重复点击
		return;
	}
	if(f ==''){
		$.each(play_main.play, function (index, value ){
			value.follow_name = index;
			play_follow       = value;
			return false;
		})
	}else{
		$.each(play_main.play, function (index, value ){
			if(f == index){
				value.follow_name = index;
				play_follow       = value;
				return false;
			}
		})
	}
	
	user_play = play_main.main_name + '-' + play_follow.follow_name;
	betting[user_play]    = {
			'one'   : new Array(),
			'two'   : new Array(),
			'three' : new Array(),
	};
	oddsArr.length       = 0;
	$('#id_bet_example').html(play_follow.example);
	// 清除预投注项内容
	betting[user_play].one.length   = 0;
	betting[user_play].two.length   = 0;
	betting[user_play].three.length = 0;
	// 用户当前选择的玩法信息
	var npType  = resData.codeKeyList[play_main.main_name + '-'][play_main.main_name + '|'];
	var nowPlay = resData.codeKeyList[play_main.main_name + '-'][play_main.main_name + '|'][play_follow.follow_name];
	// 动态读取该用户在当前彩种玩法中的实际赔率信息
	if(!$.isEmptyObject(nowPlay)){
		// 选择从玩法，加载从玩法方式内容与说明
		$('.tag_play_explain').html(nowPlay.explain);
		$('.tag_pc_bonus').html(nowPlay.odds);
		$('.tag_exp_odds').html(nowPlay.odds);
	}else{
		$('.hoverContent table').html('');
		// 玩法中，赔率随投注内容而变化的情况 
		var jiangjinxiangqing = '<tr><th>猜中</th><th>单注最高奖金</th></tr>';
		$('.hoverContent table').append(jiangjinxiangqing);
		$.each(npType, function (i, v){
			if(v['foll_encode'].indexOf(play_follow.follow_name) != -1){
				jiangjinxiangqing = '<tr class="tag_tmp_odds_remark"><td>' + v.foll_title + '</td><td>' + v.odds + '<td></tr>';
				$('.hoverContent table').append(jiangjinxiangqing);
			}
		})
		// 选择从玩法，加载从玩法方式内容与说明
		$('.tag_play_explain').html('多重玩法');
	}
	
	set_play_body();
}

/**
 * 设置玩法内容界面
 * @param main_play: 主玩法
 * @param follow_play: 从玩法
 */
function set_play_body(){
	$('.tag_play_content').html(function (){
		var content  = '';
		if(play_follow.item.option == 'import'){
			// 导入界面
			content += '<div class="textareaNumber">';
			content += '	<div class="numberImport">';
			content += '		<a href="javascript:void(0);"  class="submitBtn tag_import_betting">导入注单</a> ';
			content += '		<input type="file" class="tag_import_filebtn" style="display: none;" />'; 
			content += '		<a href="javascript:void(0);"  class="selectEg">查看标准格式样本 </a> ';
			content += '		<div class="EgContent">';
			content += '			<ul>';
			content += '				<li>01 02 03</li>';
			content += '				<li>03 07 09</li>';
			content += '				<li>02 05 08</li>';
			content += '				<li>04 05 06</li>';
			content += '			</ul>';
			content += '		</div>';
			content += '	</div> ';
			content += '	<div class="fileUpload"></div>'; 
			content += '	<div class="numberTextarea">';
			content += '		<textarea class="betNote tag_import_content" name="reday_bet"></textarea>'; 
			content += '		<p class="noteTip tag_import_tips"> 说明： <br /> 1、请参照&quot;标准格式样本&quot;格式录入或上传方案。 <br /> 2、每一注号码之间请使用空格分开，每注之间以回车、逗号或分号进行分隔 <br /> 3、文件格式必须是.txt格式。 <br /> 4、文件较大时会导致上传时间较长，请耐心等待！ <br /> 5、导入文本内容后将覆盖文本框中现有的内容。 </p>';
			content += '	</div> ';
			content += '	<div class="numberBtn">';
			content += '		<a href="javascript:void(0);"  class="submitBtn tag_clear_error">删除错误项</a>&nbsp;'; 
			content += '		<a href="javascript:void(0);"  class="submitBtn tag_check_import">检查格式是否正确</a>&nbsp;'; 
			content += '		<a href="javascript:void(0);"  class="submitBtn tag_import_func_clear">清空文本框</a>';
			content += '	</div>';
			content += '</div>';
		}else{
			content += '<div class="sscCheckNumber">';
			content += '	<ul>';
			content += '		<li>';
			$.each(play_follow.item, function (index, value){
				content += '		<div class="fix selectSYX5">';
				if(value.name){
					content += '		<span class="buyNumberTitle">' + value.name + '<i></i></span>';
				}
				if(value.option == 'baseItem'){
					content += '			<div class="buyNumber fix">';
					// 引用公共设置的选项内容
					$.each(resData.playItem.baseItem, function (i, v){
						// 赔率还是使用自定义，不适用公共baseItem中的数据
						content += '<a href="javascript:void(0);"  id="choice_item_' + v.title +'" class="tag_choice_item" amw="' + value.winner_money + '" ami="' + v.title + '" group="' + index + '">' + v.title + '</a>';
					})
				}else{
					content += '			<div class="buyNumber fix" style="text-align: center;">';
					$.each(value.option, function (oi, ov){
						content += '<' + value.lable + ' class="tag_choice_item" amw="' + ov.winner_money + '" ami="' + ov.title + '"" group="' + index + '">' + ov.title + '</' + value.lable + '>';
					})
				}
				content += '			</div>';
				if(value.func == 'funcItem'){
					content += '		<div class="buyNumberFilter">';
					$.each(resData.playItem.funcItem, function (fi, fv){
						content += '<a href="javascript:void(0);"  class="tag_func_btn" ami="' + fv.ami + '" group="' + index + '">' + fv.title + '</a>';
					})
					content += '		</div>';
				}
				content += '		</div>';
			})
			content += '		</li>';
			content += '	</ul>';
			content += '</div>';
		}
		return content;
	});
	$('.tag_bet_operation').html(function (){
		default_bet_money = resData.playItem.bet_money_info.base_money;
		var str = '	<p class="betTotal">';
		str += '	您选择了<em class="tag_bet_count">0</em> 注，';
		str += '	<em class="inputAdd fix">';
		str += '		<i class="off tag_betnum_subtract">-</i> ';
		str += '		<input type="tel" value="1" class="tag_betnum"> ';
		str += '		<i class="tag_betnum_add">+</i>';
		str += '	</em> 倍';
		str += '	<select style="position: static; opacity: 10;" class="tag_money_unit">';
		$.each(resData.playItem.bet_money_info.money_unit, function (i,v){
			bet_money_unit = bet_money_unit ? bet_money_unit : i;
			str += '<option value="' + v.amount + '" ami="' + i + '">' + v.title + '</option>';
		})
		str += '	</select>';
		str += '	共 <i class="tag_show_bet_amount">0.00</i>元';
		str += '</p>';
		str += '<a href="javascript:void(0);"  class="betBtn tag_selection_bet">确认选号</a>';
		return str;
	});
	// 测试使用部分：自动填充内容， 不需要手动上传投注内容
//	test_import();
	// 检查输入内容
	check_import_betting();
}

//倒计时结束提示弹框
function layer_msg(title, msg, type){
	if(!title){return}
	switch(type){
		case 'submit':
			var bet_status = false;
			layer.open({
				title: title,
				content: msg,
				className: 'layui-m-tag-msg',
				btn: ['投注','取消'],
				yes: function (index){
					// 提交投注请求
					var param  = 'lottery=k3';
						param += '&play=' + choice_k3_play;
						param += '&betting=' + betting[user_play];
						param += '&no=' + resData.data.lotting.id;
						param += '&eo_money=' + $('.tag_betting_pay_everyone').val();
						param += '&lott_id=' + $('#choice_play_id').val();
					$.ajax({  
		        		type:'post',    
		        	    url:betUrl,  
		        	    data:param,  
		        	    cache:false,  
		        	    dataType:'json',  
		        	    async:false,
		        	    success:function(res){  
		        	    	if(res.status == 'success'){
		        	    		bet_status = true;
		            	    }
		        	    }  
		        	})
		        	layer.close(index);
		        	if(bet_status){
						layer_msg('温馨提示', '<span style="color:red">投注成功</span>，您可以在我的账户查看注单详情', 'success');
			    		clear_betting();
					}else{
						layer_msg('温馨提示', '投注失败，请重试', '');
					}
				}
			});
			break;
		case 'success':
			layer.open({
	            title: '温馨提示',
	            content: '<span style="color:red">投注成功</span>，您可以在我的账户查看注单详情',
	            className: 'layui-m-tag-msg',
	            btn: ['确定'],
	            yes: function (index){
					// 继续投注
	            	layer.close(index);
	            },
	        });
			break;
		default:
			layer.open({
				title: title,
				content: msg,
				className: 'layui-m-tag-msg',
				btn: ['确定'],
				yes: function (index){
					layer.close(index);
				}
			});
			break;
	}
}

/**
 * 方便写代码测试
 */
function test_import(){
	var str = '01 06 09 \r\n10 11 02 \r\n12 11 01 \r\n1  02 50';
	$('.tag_play_content .tag_import_content').text(str);
	$('.tag_play_content .tag_import_tips').hide();
}

/**
 * 检查导入投注内容是否符合规则
 */
var ready_bet       = {};   // 预投注项对象
var ready_bet_index = 1;    // 每次确定选号都加入到预投注项中，同彩种同玩法一样
function check_import_betting(){
	var tmp         = [];
	var import_str  = $('.tag_import_content').val();
	if(!import_str) { return; }
	// 解析提交内容
	var outer       = import_str.split('\n');
	var bt          = '';
	var item        = [];
	var checkRepeat = [];
	
	$.each(outer, function (i, v){
		if(!v){ return true; }
		// 半初始化数据
		item       = {
				'bet': [],
				'check': 'success',
				'unit': [],
		};
		bt = v.split(' ');
		// 清除多余数据（主要是空格数据）
		var tmp_index = 0;
		$.each(bt, function (bi, bv){
			bv    = (bv.trim()).replace('\r\n','');
			if(bv == ''){ return true; }
			if(bv < 1 || bv > 11 || ($.inArray(bv, item.bet) > -1) || isNaN(bv)){
				// 正常数值检查
				item.check   = 'error';
			}
			item.bet.push(bv);
			if(tmp_index == 0){
				betting[user_play].one.push(bv);
			}else if(tmp_index == 1){
				betting[user_play].two.push(bv);
			}else if(tmp_index == 2){
				betting[user_play].three.push(bv);
			}
			tmp_index++;
		})
		oddsArr.push(play_follow.item.winner_money);
		tmp.push(item);
	})
	ready_bet[ready_bet_index] = {'bet_name': user_play, 'bet_item': tmp, 'bet_unit': 0, 'bet_money_unit': 0, 'bet_zhushu': 0, 'bet_beishu': 0, 'maxwinner': 0, 'period':resData.lotting.period, 'bet_amount':'', 'betting':betting[user_play] };
	// 玩法中每注号码中号码数量必须是nums才符合当前选择玩法
	var nums = 0;
	switch(play_main.main_name + '-' + play_follow.follow_name){
		case 'SM-QS_ZHI_XDS':
			// 三码玩法：前三直选单式
		case 'SM-QS_ZU_XDS':
			// 三码玩法：前三组选单式
			nums = 3;
			break;
		case 'EM-QE_ZHI_XDS':
			// 二码玩法：前二直选单式
		case 'EM-QE_ZU_XDS':
			// 二码玩法：前二组选单式
			nums = 2;
			break;
		case 'RXDS-YZY':
			// 任选单式：一中一
			nums = 1;
			break;
		case 'RXDS-EZE':
			// 任选单式：二中二
			nums = 2;
			break;
		case 'RXDS-SZS':
			// 任选单式：三中三
			nums = 3;
			break;
		case 'RXDS-SI_Z_SI':
			// 任选单式：四中四
			nums = 4;
			break;
		case 'RXDS-WZW':
			// 任选单式：五中五
			nums = 5;
			break;
		case 'RXDS-LZW':
			// 任选单式：六中五
			nums = 6;
			break;
		case 'RXDS-QZW':
			// 任选单式：七中五
			nums = 7;
			break;
		case 'RXDS-BZW':
			// 任选单式：八中五
			nums = 8;
			break;
		default:
			break;
	}
	$.each(ready_bet[ready_bet_index].bet_item, function (i, v){
		if(v.bet.length != nums){
			ready_bet[ready_bet_index].bet_item[i].check = 'error';
		}
	})
	bet_jisuan();
}

// 检查预投注项的格式
function check_bet_error(){
	var msg  = '以下投注格式不正确：<br/>';
	var flag = 'success';
	$.each(ready_bet, function (i, v){
		if(v.check == 'error'){
			msg += v.bet.join(' ') + ',';
			flag = 'error';
		}
	})
	if(flag == 'success'){
		msg = '全部投注格式正确,';
	}
	layer_msg('温馨提示', msg.substr(0, msg.length - 1), '');
	return flag;
}

// 手动投注，检查有效的投注号
function check_valid_bet(obj='', func=''){
	// 初始化预投注项对象
	var tmp        = {};
	var item       = {
			'bet': [],
			'check': 'success',
	};
	var index      = 0;
	// 解读预投注信息为ready_bet格式
	ready_bet[ready_bet_index]   = {'bet_name': user_play, 'bet_item': {}, 'bet_unit': 0, 'bet_money_unit': 0, 'bet_zhushu': 0, 'bet_beishu': 0, 'maxwinner': 0, 'period':resData.lotting.period, 'bet_amount':'', 'betting':betting[user_play] };
	var mast_choice_num_controll = 0;
	switch(play_main.main_name + '-' + play_follow.follow_name){
		case 'SM-QS_ZHI_XFS':
			// 三码玩法：前三直选复式
			$.each(betting[user_play].one, function (i1, v1){
				$.each(betting[user_play].two, function (i2, v2){
					$.each(betting[user_play].three, function (i3, v3){
						item.bet         = [];
						item.bet.push(v1);
						item.check       = $.inArray(v2, item.bet) >= 0 ? 'error' : 'success';
						item.bet.push(v2);
						item.check       = ($.inArray(v3, item.bet) >= 0 || item.check == 'error') ? 'error' : 'success';
						item.bet.push(v3);
						// 跳过当前，继续循环
						if(item.check == 'error') return true;
						tmp[index]       = {'bet':item.bet, 'check':item.check};
						index++;
					})
				})
			})
			break;
		case 'SM-QS_ZU_XFS':
			// 三码玩法：前三组选复式
			for(var i = 0; i < betting[user_play].one.length - 2; i++){
				for(var j = i+1; j < betting[user_play].one.length; j++){
					for(var z = j+1; z < betting[user_play].one.length; z++){
						tmp[index]    = {'bet':[betting[user_play].one[i], betting[user_play].one[j], betting[user_play].one[z]], 'check':'success'};
						index++;
					}
				}
			}
			break;
		case 'SM-QS_ZU_XDT':
			// 这里检查是两组选项中是否有冲突项
			
			if($(obj).attr('group') == 1 && betting[user_play].one.length > 2){
				// 胆码最多两个，超过两个则把上次选中的值踢出
				var bet_now = betting[user_play].one.pop();
				var bet_out = betting[user_play].one.pop();
				betting[user_play].one.push(bet_now);
				// 更新选中样式
				$('#choice_item_' + bet_out).removeClass('curr');
			}
			var otherBetArr = '';
			var otherGroup  = 1;
			if($(obj).attr('group') == 1){
				otherBetArr = betting[user_play].two;
				otherGroup  = 2;
			}else{
				otherBetArr = betting[user_play].one;
			}
			
			// 检查当前选择的投注数值是否已经存在点亮的数据中
			if($.inArray($(obj).attr('ami'), otherBetArr) > -1){
				// 删除重复数据
				otherBetArr.splice(($.inArray($(obj).attr('ami'), otherBetArr)), 1);
				// 改变选中样式
				$('#choice_item_' + $(obj).attr('ami') + '[group="' + otherGroup + '"]').removeClass('curr');
			}
			// 三码玩法：前三组选胆拖【胆码最多两个，胆拖可多个，并且胆码胆拖整体不重复数】
			if(parseInt(betting[user_play].one.length + betting[user_play].two.length) < 3){
				// 三个起
				break;
			}
			if(func){
				switch(func){
					case 'da':
					case 'xiao':
					case 'ji':
					case 'ou':
						$.each(betting[user_play].one, function (i, v){
							var checkRep = $.inArray(v, betting[user_play].two);
							if(checkRep > -1){
								// 功能性按键优先，剔除胆组的重复项
								betting[user_play].one.splice(i, 1);
								// 重设被踢出项的样式
								$('#choice_item_' + v + '[group="' + otherGroup + '"]').removeClass('curr');
							}
						})
						break;
					case 'qing':
						break;
					default:
						// 如果请求来自功能性按键， 清空另一个选码项，并改变选择样式
						$('.tag_choice_item[group="' + otherGroup + '"]').removeClass('curr');
						if($(obj).attr('group') == 1){
							betting[user_play].two.length = 0;
						}else{
							betting[user_play].one.length = 0;
						}
						break;
				}
			}else{
				if($(obj).attr('group') == 1){
					betting[user_play].two = otherBetArr;
				}else{
					betting[user_play].one = otherBetArr;
				}
			}
			if(betting[user_play].one.length == 2){
				// 二胆拖一码
				$.each(betting[user_play].two, function (i, v){
					tmp[index]    = {'bet':[betting[user_play].one[0], betting[user_play].one[1], v], 'check':'success'};
					index++;
				})
			}else{
				// 一胆拖二码
				for(var i1 = 0; i1 < betting[user_play].one.length; i1++){
					for(var i2 = 0; i2 < betting[user_play].two.length; i2++){
						for(var i3 = i2 + 1; i3 < betting[user_play].two.length; i3++){
							tmp[index]    = {'bet':[betting[user_play].one[i1], betting[user_play].two[i2], betting[user_play].two[i3]], 'check':'success'};
							index++;
						}
					}
				}
			}
			break;
		case 'EM-QE_ZHI_XFS':
			// 二码玩法：前二直选复式
			var check = 'success';
			$.each(betting[user_play].one, function (i1, v1){
				$.each(betting[user_play].two, function (i2, v2){
					check = 'success';
					if(v1 == v2) {
						check = 'error';
					}
					tmp[index]    = {'bet':[v1, v2], 'check':check};
					index++;
				})
			})
			break;
		case 'EM-QE_ZU_XFS':
			// 二码玩法：前二组选复式
			for(var i = 0; i < betting[user_play].one.length - 1; i++){
				for(var j = i+1; j < betting[user_play].one.length; j++){
					tmp[index]    = {'bet':[betting[user_play].one[i], betting[user_play].one[j]], 'check':'success'};
					index++;
				}
			}
			break;
		case 'EM-QE_ZU_XDT':
			// 二码玩法：前二组选胆拖【胆码最多两个，胆拖可多个，并且胆码胆拖整体不重复数】
			if(parseInt(betting[user_play].one.length + betting[user_play].two.length) < 2){
				// 两个起
				break;
			}
			if($(obj).attr('group') == 1 && betting[user_play].one.length > 1){
				// 胆码最多两个，超过两个则把上次选中的值踢出
				var bet_now = betting[user_play].one.pop();
				var bet_out = betting[user_play].one.pop();
				betting[user_play].one.push(bet_now);
				// 更新选中样式
				$('#choice_item_' + bet_out).removeClass('curr');
			}
			var otherBetArr = '';
			var otherGroup  = 1;
			if($(obj).attr('group') == 1){
				otherBetArr = betting[user_play].two;
				otherGroup  = 2;
			}else{
				otherBetArr = betting[user_play].one;
			}
			if(func){
				// 如果请求来自功能性按键， 清空另一个选码项，并改变选择样式
				$('.tag_choice_item[group="' + otherGroup + '"]').removeClass('curr');
				if($(obj).attr('group') == 1){
					betting[user_play].two.length = 0;
				}else{
					betting[user_play].one.length = 0;
				}
			}else{
				// 检查当前选择的投注数值是否已经存在点亮的数据中
				if($.inArray($(obj).attr('ami'), otherBetArr) > -1){
					// 删除重复数据
					otherBetArr.splice(($.inArray($(obj).attr('ami'), otherBetArr)), 1);
					// 改变选中样式
					$('#choice_item_' + $(obj).attr('ami') + '[group="' + otherGroup + '"]').removeClass('curr');
				}
				if($(obj).attr('group') == 1){
					betting[user_play].two = otherBetArr;
				}else{
					betting[user_play].one = otherBetArr;
				}
			}
			$.each(betting[user_play].one, function (i1, v1){
				$.each(betting[user_play].two, function (i2, v2){
					tmp[index]    = {'bet':[v1, v2], 'check':'success'};
					index++;
				})
			})
			break;
		case 'BDW-QSYMBDW':
			// 不定位：前三一码不定位
			$.each(betting[user_play].one, function (i, v){
				tmp[index]    = {'bet':[v], 'check':'success'};
				index++;
			})
			break;
		case 'DWD-FS':
			// 定位胆：复式
			$.each(betting[user_play].one, function (i1, v1){
				// 第一个位置的投注项
				tmp[index]    = {'bet':[v1, '', ''], 'check':'success'};
				index++;
			})
			$.each(betting[user_play].two, function (i2, v2){
				// 第一个位置的投注项
				tmp[index]    = {'bet':['', v2, ''], 'check':'success'};
				index++;
			})
			$.each(betting[user_play].three, function (i3, v3){
				// 第一个位置的投注项
				tmp[index]    = {'bet':['', '', v3], 'check':'success'};
				index++;
			})
				
			break;
		case 'QWX-DDS':
			// 趣味型：定单双
		case 'QWX-CZW':
			// 趣味型：猜中位
			$.each(betting[user_play].one, function (i1, v1){
				// 第一个位置的投注项
				tmp[index]    = {'bet':[v1], 'check':'success'};
				index++;
			})
			break;
		case 'RXFS-YZY':
			// 任选复式：一中一
			$.each(betting[user_play].one, function (i1, v1){
				// 第一个位置的投注项
				tmp[index]    = {'bet':[v1], 'check':'success'};
				index++;
			})
			nums = 1;
			break;
		case 'RXFS-EZE':
			// 任选复式：二中二
			for(var i = 0; i < betting[user_play].one.length - 1; i++){
				for(var j = i+1; j < betting[user_play].one.length; j++){
					tmp[index]    = {'bet':[betting[user_play].one[i], betting[user_play].one[j]], 'check':'success'};
					index++;
				}
			}
			break;
		case 'RXFS-SZS':
			// 任选复式：三中三   
			for(var i = 0; i < betting[user_play].one.length - 2; i++){
				for(var j = i+1; j < betting[user_play].one.length; j++){
					for(var z = j+1; z < betting[user_play].one.length; z++){
						tmp[index]    = {'bet':[betting[user_play].one[i], betting[user_play].one[j], betting[user_play].one[z]], 'check':'success'};
						index++;
					}
				}
			}
			break;
		case 'RXFS-SI_Z_SI':
			// 任选复式：四中四
			for(var i = 0; i < betting[user_play].one.length - 3; i++){
				for(var j = i+1; j < betting[user_play].one.length; j++){
					for(var z = j+1; z < betting[user_play].one.length; z++){
						for(var x = z+1; x < betting[user_play].one.length; x++){
							tmp[index]    = {'bet':[betting[user_play].one[i], betting[user_play].one[j], betting[user_play].one[z], betting[user_play].one[x]], 'check':'success'};
							index++;
						}
					}
				}
			}
			break;
		case 'RXFS-WZW':
			// 任选复式：五中五
			for(var i = 0; i < betting[user_play].one.length - 4; i++){
				for(var j = i+1; j < betting[user_play].one.length; j++){
					for(var z = j+1; z < betting[user_play].one.length; z++){
						for(var x = z+1; x < betting[user_play].one.length; x++){
							for(var c = x+1; c < betting[user_play].one.length; c++){
								tmp[index]    = {'bet':[betting[user_play].one[i], betting[user_play].one[j], betting[user_play].one[z], betting[user_play].one[x], betting[user_play].one[c]], 'check':'success'};
								index++;
							}
						}
					}
				}
			}
			break;
		case 'RXFS-LZW':
			// 任选复式：六中五
			for(var i = 0; i < betting[user_play].one.length - 5; i++){
				for(var j = i+1; j < betting[user_play].one.length; j++){
					for(var z = j+1; z < betting[user_play].one.length; z++){
						for(var x = z+1; x < betting[user_play].one.length; x++){
							for(var c = x+1; c < betting[user_play].one.length; c++){
								for(var v = c+1; v < betting[user_play].one.length; v++){
									tmp[index]    = {'bet':[betting[user_play].one[i], betting[user_play].one[j], betting[user_play].one[z], betting[user_play].one[x], betting[user_play].one[c], betting[user_play].one[v]], 'check':'success'};
									index++;
								}
							}
						}
					}
				}
			}
			break;
		case 'RXFS-QZW':
			// 任选复式：七中五
			for(var i = 0; i < betting[user_play].one.length - 6; i++){
				for(var j = i+1; j < betting[user_play].one.length; j++){
					for(var z = j+1; z < betting[user_play].one.length; z++){
						for(var x = z+1; x < betting[user_play].one.length; x++){
							for(var c = x+1; c < betting[user_play].one.length; c++){
								for(var v = c+1; v < betting[user_play].one.length; v++){
									for(var b = v+1; b < betting[user_play].one.length; b++){
										tmp[index]    = {'bet':[betting[user_play].one[i], betting[user_play].one[j], betting[user_play].one[z], betting[user_play].one[x], betting[user_play].one[c], betting[user_play].one[v], betting[user_play].one[b]], 'check':'success'};
										index++;
									}
								}
							}
						}
					}
				}
			}
			break;
		case 'RXFS-BZW':
			// 任选复式：八中五
			for(var i = 0; i < betting[user_play].one.length - 7; i++){
				for(var j = i+1; j < betting[user_play].one.length; j++){
					for(var z = j+1; z < betting[user_play].one.length; z++){
						for(var x = z+1; x < betting[user_play].one.length; x++){
							for(var c = x+1; c < betting[user_play].one.length; c++){
								for(var v = c+1; v < betting[user_play].one.length; v++){
									for(var b = v+1; b < betting[user_play].one.length; b++){
										for(var n = b+1; n < betting[user_play].one.length; n++){
											tmp[index]    = {'bet':[betting[user_play].one[i], betting[user_play].one[j], betting[user_play].one[z], betting[user_play].one[x], betting[user_play].one[c], betting[user_play].one[v], betting[user_play].one[b], betting[user_play].one[n]], 'check':'success'};
											index++;
										}
									}
								}
							}
						}
					}
				}
			}
			break;
		case 'RXDT-EZE':
			if(!checkDT_repeat(obj, func, 1, 2)){
				break;
			}
			
			for(var i = 0; i < betting[user_play].two.length; i++){
				tmp[index]    = {'bet':[betting[user_play].one[0], betting[user_play].two[i]], 'check':'success'};
				index++;
			}
			break;
		case 'RXDT-SZS':
			if(!checkDT_repeat(obj, '', 1, 3)){
				break;
			}
			if($(obj).attr('group') == 1 && betting[user_play].one.length > 1){
				var bet_now        = betting[user_play].one.pop();
				var bet_out        = betting[user_play].one.pop();
				betting[user_play].one.push(bet_now);
				$('#choice_item_' + bet_out).removeClass('curr');
			}
			for(var i = 0; i < betting[user_play].two.length; i++){
				for(var o = i + 1; o < betting[user_play].two.length; o++){
					tmp[index]    = {'bet':[betting[user_play].one[0], betting[user_play].two[i], betting[user_play].two[o]], 'check':'success'};
					index++;
				}
			}
			break;
		case 'RXDT-SI_Z_SI':
			if(!checkDT_repeat(obj, '', 1, 4)){
				break;
			}
			if($.inArray(betting[user_play].one[0], betting[user_play].two) > -1){
				// 第二组选项全选，清空第一组
				var bet_out        = betting[user_play].one.pop();
				$('#choice_item_' + bet_out + '[group="1"]').removeClass('curr');
				break;
			}
			if($(obj).attr('group') == 1 && betting[user_play].one.length > 1){
				var bet_now        = betting[user_play].one.pop();
				var bet_out        = betting[user_play].one.pop();
				betting[user_play].one.push(bet_now);
				$('#choice_item_' + bet_out).removeClass('curr');
			}
			for(var i = 0; i < betting[user_play].two.length; i++){
				for(var o = i + 1; o < betting[user_play].two.length; o++){
					for(var p = o + 1; p < betting[user_play].two.length; p++){
						tmp[index]    = {'bet':[betting[user_play].one[0], betting[user_play].two[i], betting[user_play].two[o], betting[user_play].two[p]], 'check':'success'};
						index++;
					}
				}
			}
			break;
		case 'RXDT-WZW':
			if(!checkDT_repeat(obj, '', 1, 5)){
				break;
			}
			if($.inArray(betting[user_play].one[0], betting[user_play].two) > -1){
				// 第二组选项全选，清空第一组
				var bet_out        = betting[user_play].one.pop();
				$('#choice_item_' + bet_out + '[group="1"]').removeClass('curr');
				break;
			}
			if($(obj).attr('group') == 1 && betting[user_play].one.length > 1){
				var bet_now        = betting[user_play].one.pop();
				var bet_out        = betting[user_play].one.pop();
				betting[user_play].one.push(bet_now);
				$('#choice_item_' + bet_out).removeClass('curr');
			}
			for(var i = 0; i < betting[user_play].two.length; i++){
				for(var o = i + 1; o < betting[user_play].two.length; o++){
					for(var p = o + 1; p < betting[user_play].two.length; p++){
						for(var z = p + 1; z < betting[user_play].two.length; z++){
							tmp[index]    = {'bet':[betting[user_play].one[0], betting[user_play].two[i], betting[user_play].two[o], betting[user_play].two[p], betting[user_play].two[z]], 'check':'success'};
							index++;
						}
					}
				}
			}
			break;
		case 'RXDT-LZW':
			if(!checkDT_repeat(obj, '', 1, 6)){
				break;
			}
			if($.inArray(betting[user_play].one[0], betting[user_play].two) > -1){
				// 第二组选项全选，清空第一组
				var bet_out        = betting[user_play].one.pop();
				$('#choice_item_' + bet_out + '[group="1"]').removeClass('curr');
				break;
			}
			if($(obj).attr('group') == 1 && betting[user_play].one.length > 1){
				var bet_now        = betting[user_play].one.pop();
				var bet_out        = betting[user_play].one.pop();
				betting[user_play].one.push(bet_now);
				$('#choice_item_' + bet_out).removeClass('curr');
			}
			for(var i = 0; i < betting[user_play].two.length; i++){
				for(var o = i + 1; o < betting[user_play].two.length; o++){
					for(var p = o + 1; p < betting[user_play].two.length; p++){
						for(var z = p + 1; z < betting[user_play].two.length; z++){
							for(var x = z + 1; x < betting[user_play].two.length; x++){
								tmp[index]    = {'bet':[betting[user_play].one[0], betting[user_play].two[i], betting[user_play].two[o], betting[user_play].two[p], betting[user_play].two[z], betting[user_play].two[x]], 'check':'success'};
								index++;
							}
						}
					}
				}
			}
			break;
		case 'RXDT-QZW':
			if(!checkDT_repeat(obj, '', 1, 7)){
				break;
			}
			if($.inArray(betting[user_play].one[0], betting[user_play].two) > -1){
				// 第二组选项全选，清空第一组
				var bet_out        = betting[user_play].one.pop();
				$('#choice_item_' + bet_out + '[group="1"]').removeClass('curr');
				break;
			}
			if($(obj).attr('group') == 1 && betting[user_play].one.length > 1){
				var bet_now        = betting[user_play].one.pop();
				var bet_out        = betting[user_play].one.pop();
				betting[user_play].one.push(bet_now);
				$('#choice_item_' + bet_out).removeClass('curr');
			}
			for(var i = 0; i < betting[user_play].two.length; i++){
				for(var o = i + 1; o < betting[user_play].two.length; o++){
					for(var p = o + 1; p < betting[user_play].two.length; p++){
						for(var z = p + 1; z < betting[user_play].two.length; z++){
							for(var x = z + 1; x < betting[user_play].two.length; x++){
								for(var c = x + 1; c < betting[user_play].two.length; c++){
									tmp[index]    = {'bet':[betting[user_play].one[0], betting[user_play].two[i], betting[user_play].two[o], betting[user_play].two[p], betting[user_play].two[z], betting[user_play].two[x], betting[user_play].two[c]], 'check':'success'};
									index++;
								}
							}
						}
					}
				}
			}
			break;
		case 'RXDT-BZW':
			if(!checkDT_repeat(obj, '', 1, 8)){
				break;
			}
			if($.inArray(betting[user_play].one[0], betting[user_play].two) > -1){
				// 第二组选项全选，清空第一组
				var bet_out        = betting[user_play].one.pop();
				$('#choice_item_' + bet_out + '[group="1"]').removeClass('curr');
				break;
			}
			if($(obj).attr('group') == 1 && betting[user_play].one.length > 1){
				var bet_now        = betting[user_play].one.pop();
				var bet_out        = betting[user_play].one.pop();
				betting[user_play].one.push(bet_now);
				$('#choice_item_' + bet_out).removeClass('curr');
			}
			for(var i = 0; i < betting[user_play].two.length; i++){
				for(var o = i + 1; o < betting[user_play].two.length; o++){
					for(var p = o + 1; p < betting[user_play].two.length; p++){
						for(var z = p + 1; z < betting[user_play].two.length; z++){
							for(var x = z + 1; x < betting[user_play].two.length; x++){
								for(var c = x + 1; c < betting[user_play].two.length; c++){
									for(var v = c + 1; v < betting[user_play].two.length; v++){
										tmp[index]    = {'bet':[betting[user_play].one[0], betting[user_play].two[i], betting[user_play].two[o], betting[user_play].two[p], betting[user_play].two[z], betting[user_play].two[x], betting[user_play].two[c], betting[user_play].two[v]], 'check':'success'};
										index++;
									}
								}
							}
						}
					}
				}
			}
			break;
		default:
			break;
	}
	ready_bet[ready_bet_index].bet_item = tmp;
	bet_jisuan();
}
 
/**
 * 根据预投注内容计算有效投注数
 */
var valid_betnum = 0;
var js_bet_item  = { 'one':[], 'two':[], 'three':[]};
function bet_jisuan(){
	// 有效的投注数
	var valid_betnum = 0;
	if($.isEmptyObject(ready_bet) || $.isEmptyObject(ready_bet[ready_bet_index].bet_item)){
		$('.tag_bet_count').html(valid_betnum);
		return;
	}
	$.each(ready_bet[ready_bet_index].bet_item, function (i, v){
		if(v.check == 'success') valid_betnum++;
		// 倍数
		ready_bet[ready_bet_index].bet_item[i].multiple = $('.tag_betnum').val();
		// 金额
		ready_bet[ready_bet_index].bet_item[i].eo_money = default_bet_money;
	})
	
	$('.tag_bet_count').html(valid_betnum);
	// 开始计算金额:  默认每注金额 * 金额单位 * 投注组数 * 投注倍数
	var amount = parseFloat(default_bet_money * $('.tag_money_unit').val() * valid_betnum * $('.tag_betnum').val()).toFixed(2);
	ready_bet[ready_bet_index].lott_id     = resData.lotteryInfo.id;
	ready_bet[ready_bet_index].bet_unit    = $('.tag_money_unit').find("option:selected").text();
	ready_bet[ready_bet_index].bet_zhushu  = valid_betnum;
	ready_bet[ready_bet_index].bet_beishu  = $('.tag_betnum').val();
	ready_bet[ready_bet_index].bet_money_unit= $('.tag_money_unit').find("option:selected").val();
	ready_bet[ready_bet_index].bet_amount  = parseFloat(amount).toFixed(2);
	ready_bet[ready_bet_index].maxwinner   = (parseInt($('.tag_betnum').val()) * oddsArr[0] * parseFloat($('.tag_money_unit').val())).toFixed(2);
	ready_bet[ready_bet_index].betting     = betting[user_play];
	ready_bet[ready_bet_index].period      = resData.lotting.id;
	ready_bet[ready_bet_index].eo_money    = default_bet_money;
	$('.tag_show_bet_amount').html(amount);
}

/**
 * 胆拖玩法中，  第一组与第二种不允许重复选号，如果重复，清掉对面组选中的同号
 * @param minNum【胆拖最多数】
 */
function checkDT_repeat(obj, func, dtNum, allNum){
	if($(obj).attr('group') == 1 && betting[user_play].one.length > dtNum){
		// 胆码最多两个，超过两个则把上次选中的值踢出
		var bet_now = betting[user_play].one.pop();
		var bet_out = betting[user_play].one.pop();
		betting[user_play].one.push(bet_now);
		// 更新选中样式
		$('#choice_item_' + bet_out).removeClass('curr');
	}
	var otherBetArr = '';
	var otherGroup  = 1;
	if($(obj).attr('group') == 1){
		otherBetArr = betting[user_play].two;
		otherGroup  = 2;
	}else{
		otherBetArr = betting[user_play].one;
	}
	if(func){
		switch(func){
			case 'da':
			case 'xiao':
			case 'ji':
			case 'ou':
//				console.log(betting[user_play].one);
				$.each(betting[user_play].one, function (i, v){
					var checkRep = $.inArray(v, betting[user_play].two);
					if(checkRep > -1){
						// 功能性按键优先，剔除胆组的重复项
						betting[user_play].one.splice(i, 1);
						// 重设被踢出项的样式
						$('#choice_item_' + v + '[group="1"]').removeClass('curr');
					}
				})
				break;
			case 'qing':
				break;
			default:
				// 如果请求来自功能性按键， 清空另一个选码项，并改变选择样式
				$('.tag_choice_item[group="' + otherGroup + '"]').removeClass('curr');
				betting[user_play].one.length = 0;
				break;
		}
	}else{
		// 检查当前选择的投注数值是否已经存在点亮的数据中
		if($.inArray($(obj).attr('ami'), otherBetArr) > -1){
			// 删除重复数据
			otherBetArr.splice(($.inArray($(obj).attr('ami'), otherBetArr)), 1);
			// 改变选中样式
			$('#choice_item_' + $(obj).attr('ami') + '[group="' + otherGroup + '"]').removeClass('curr');
		}
		if($(obj).attr('group') == 1){
			betting[user_play].two = otherBetArr;
		}else{
			betting[user_play].one = otherBetArr;
		}
	}
	if(parseInt(betting[user_play].one.length + betting[user_play].two.length) < allNum){
		// 总数allNum起
		return false;
	}
	if(betting[user_play].one.length < 1){
		// 胆拖必须
		return false;
	}
	return true;
}

function create_bet_list (){
	var tongji_zhushu     = 0;
	var tongji_amount     = 0;
	$('.tag_checkList').html(function (){
		var str                = '';
		var ready_bet_playname = '';
		var tmp                = '';
		var tmp_betting_item   = '';
		console.log(ready_bet);
		$.each(ready_bet, function (i, v){
			if($.isEmptyObject(v)) return true;
			// 投注信息解析计算
			tmp_betting_item = '';
			if(!$.isEmptyObject(v.betting.one)){
				$.each(v.betting.one, function (i1, v1){
					tmp_betting_item += v1 + ' ';
				})
			}
			if(!$.isEmptyObject(v.betting.two)){
				tmp_betting_item += ', ';
				$.each(v.betting.two, function (i2, v2){
					tmp_betting_item += v2 + ' ';
				})
			}
			if(!$.isEmptyObject(v.betting.three)){
				tmp_betting_item += ', ';
				$.each(v.betting.three, function (i3, v3){
					tmp_betting_item += v3 + ' ';
				})
			}
			ready_bet[i].bet_string = tmp_betting_item;
			// 临时结果计算
			var beishu = $('.tag_betnum').val();
			var zhushu = 0;
			// 解析投注项的信息
			tmp = v.bet_name.split('-');
			str += '<tr>';
			str += '	<td><i class="order_type">[' + 
				resData.playItem.mainItem[tmp[0]].play_name + ',' + 
				resData.playItem.mainItem[tmp[0]].play[tmp[1]].name + 
				'] ' + tmp_betting_item + '<span>...</span></i><a href="javascript:void(0);"  class="orderDetail tag_betting_detail" amv="' + tmp_betting_item + '" m="' + tmp[0] +'" f="' + tmp[1] + '">详细</a></td>';
			$.each(v.bet_item, function (i1, v1){
				ready_bet[i].bet_item[i1].unit = {'title': $('.tag_money_unit').text(), 'value': $('.tag_money_unit').val()};
				zhushu = parseInt(i1);
			})
			zhushu++;
			tongji_zhushu++;
			tongji_amount = tongji_amount + (v.bet_beishu * v.bet_zhushu * v.bet_money_unit * default_bet_money) ;
			str += '	<td>' + ready_bet[i].bet_zhushu + '注</td>';
			str += '	<td>' + ready_bet[i].bet_beishu + '倍</td>';
			str += '	<td>' + ready_bet[i].bet_unit + '</td>';
			str += '	<td>可中金额<i class="orderMoney">' + (ready_bet[i].maxwinner) + '<i>元</i></i></td>';
			str += '	<td></td>';
			str += '	<td><i class="orderCancel tag_del_bet" ami="' + i + '">删除</i></td>';
			str += '</tr>';
		})
		return str;
	});
	// 更新投注统计信息
	$('.tag_tongji_zhushu').html(tongji_zhushu);
	$('.tag_tongji_amount').html('￥' + tongji_amount.toFixed(2));
}

/**
 * 生成追号信息列表
 * nums：追号期数
 * allcheck：是否全选
 * multiple：追号倍数基础设置
 */
function chase_main_1(nums, allcheck, multiple, checkBegin=false){
	ready_bet[ready_chase_index];
	var checked = '';
	if($('#tag_all_chase').prop('checked')){
		checked = ' checked="checked"';
	}
	// 起始期
	var begin_qi      = $('.tag_chase_fanbei').val();
	var str = '';
	var blData        = [];
	var now_preiod    = '';
	$.each(resData.chasePreiod, function (i, v){
		if (!now_preiod) now_preiod = v.id;
		if(v.id < begin_qi && checkBegin) return true;
		blData.push(v);
	});
	var dangqianqi = '';
	$.each(blData, function (i, v){
		if(i == nums) return false;
		if (v.id == now_preiod) dangqianqi = '当前期';
		str += '<tr>';
		str += '	<td>' + parseInt(i+1) + '</td>';
		str += '	<td><input type="checkbox" group="' + chaseData.chaseType + '" class="tag_main_chase_preiod" value="' + v.period + '" ' + checked + ' ami="' + v.id + '" amv="' + i + '">' + v.period + '<em>' + dangqianqi + '</em></td>';
		str += '	<td><input type="tel" group="' + chaseData.chaseType + '" ami="' + i + '" value="' + multiple + '" class="tag_main_chase_beishu"> 倍</td>;'
		str += '	<td id="tag_main_chase_item_' + chaseData.chaseType + '_' + i + '" amv="0.00">￥ 0.00元</td>';
		str += '	<td>' + v.expect_opentime + '</td>';
		str += '</tr>';
		dangqianqi = '';
	})
	return str;
}

// 翻倍追号
function chase_second(qishu=''){
	$('.tag_order_bet').hide();
	$('.tag_chase_fanbei').html(function(){
		var str        = '';
		var is_betting = '';
		$.each(resData.chasePreiod, function (i, v){
			if(i == qishu) return false;
			if(i == 0){
				is_betting = '（当前期）';
			}
			str += '<option value="' + v.id + '">' + v.period + is_betting + '</option>';
		})
		return str;
	});
}

function create_plan2(betPlan=''){
	if(betPlan == '') return;
	// 选择方案
	var plan = 0;
	$.each($('.tag_fanbei_plan'), function(i, v){
		if($(v).prop('checked')) {
			plan = i;
			return false;
		}
	})
	// 起始倍数
	var qishibeishu = $('#tag_chase_fanbei_qsbeishu').val();
	// 每隔？？期
	var every_qishu = $('#id_every_qishu').val();
	// 倍数重设（起始倍数*？？）
	var beishu_for  = $('#id_beishu_for').val();
	// 第二种方案
	// 前？？期为起始倍数
	var befor_qishu = $('#id_befor_qishu').val();
	// 后面期数为？？倍数
	var behind_beishu = $('#id_behind_beishu').val();
	if(plan == 1){
		// 第二种高级选项
		$.each($('.tag_chase_show_list:eq(1) input[class="tag_main_chase_beishu"]'), function (i, v){
			$(v).val(qishibeishu);
			$('#tag_main_chase_item_' + chaseData.chaseType.toString() + '_' + i).html('￥' + parseFloat(qishibeishu * $('#tag_main_chase_item_' + chaseData.chaseType.toString() + '_' + i).attr('amv')).toFixed(2) + '元');
			if((i + 1)%every_qishu == 0){
				qishibeishu = qishibeishu * 2;
			}
		})
	}else{
		// 其他
		$.each($('.tag_chase_show_list:eq(1) input[class="tag_main_chase_beishu"]'), function (i, v){
			if((i+1) > befor_qishu){
				qishibeishu = behind_beishu;
			}
			$(v).val(qishibeishu);
		})
	}
}

// 统计追号的期数、总金额等
function chase_tongji(group){
	var chase_beishu     = $('.tag_main_chase_beishu[group="' + group + '"]');
	var chase_base_money = $('#tag_main_chase_item_' + group + '_0').attr('amv');
	var amount           = 0;
	var beishuArr        = [];
	var tongji_qishu     = 0;
	var tongji_zhushu    = 0;
	// 单注金额统计
	var oneBetAmount     = 0;
	// 单期金额统计
	var singelAmount     = 0;
	chase_beishu.each(function(i, v){
		singelAmount     = 0;
		if($('.tag_main_chase_preiod[group="' + group + '"]:eq(' + i + ')').prop('checked') == false) return true;
		$.each(ready_bet, function (i1, v1){
			// 每期每注倍数 * 基础投注金额 * 投注金额单位 * 选号总注数
			oneBetAmount   = $(v).val() * default_bet_money * v1.bet_money_unit * v1.bet_zhushu;
			singelAmount  += oneBetAmount;
			amount        += oneBetAmount;
			tongji_zhushu += parseInt(v1.bet_zhushu);
		})
		$('#tag_main_chase_item_' + $(v).attr('group') + '_' + $(v).attr('ami')).html('￥' + singelAmount.toFixed(2) + '元');
		$('#tag_main_chase_item_' + $(v).attr('group') + '_' + $(v).attr('ami')).attr('amv', singelAmount.toFixed(2));
		beishuArr.push($(v).val());
		tongji_qishu++;
	});
	$('#id_tongji_qishu').html(tongji_qishu);
	$('#id_tongji_zhushu').html(tongji_zhushu);
	$('#id_tongji_amount').html(amount.toFixed(2));
	
	chaseData.ready_bet = [];
	chaseData.chase     = 1;
	var tmp_amount      = 0;
	var tmp             = {};
	var tmp_beishu      = 0;
	$.each($('.tag_main_chase_preiod[group="' + group + '"]'), function (i1, v1){
		if(!$(v1).prop('checked')) return true;
		tmp_beishu      = beishuArr.shift();
		$.each(ready_bet, function (bi, bv){
			tmp               = {};
			tmp.chase_period  = $(v1).attr('ami');
			tmp.chase_beishu  = tmp_beishu;
			tmp.chase_lottid  = resData.lotteryInfo.id
			if($.isEmptyObject(bv.bet_item)) return true;
			tmp.chase_bet     = bv.bet_item;
			tmp.chase_betName = bv.bet_name;
			tmp.chase_betUnit = bv.bet_money_unit;
			tmp.chase_betting = bv.bet_string;
			tmp_amount = parseFloat(tmp_amount) + parseFloat(bv.bet_amount);
			chaseData.ready_bet.push(tmp);
		})
	})
	chaseData.bet_amount = tmp_amount;
}
//安全提交
var securityPost       = true;
// 投注提交
function bet_post(obj, chase=''){
	if(securityPost == false){
		layer_msg('温馨提示', '请等待提交结果');
		return;
	}
	// 检查是否有选择投注项
	var flag    = '';
	var data    = [];
	var betData = {};
	if(chase){
		if(chaseData.qishu.length == 0){
			// 未选择追号期数
			flag = 'false';
			layer_msg('温馨提示', '追号请选择期数');
		}
		betData = {};
		betData.qishu     = chaseData.qishu;
		betData.chase     = 1;
		betData.ready_bet = chaseData.ready_bet;
		betData.bet_amount= chaseData.bet_amount;
		betData.lott_id   = resData.lotteryInfo.id;
		data.push(betData);
	}else{
		$.each(ready_bet, function (i,v){
			if($.isEmptyObject(v.bet_item)){
				// 空对象，未投注
				flag = 'false';
				return false;
			}
			betData = {};
			betData.bet_beishu   = v.bet_beishu;
			betData.bet_name     = v.bet_name;
			betData.bet_money_unit = v.bet_money_unit;
			betData.bet_zhushu   = v.bet_zhushu;
			betData.lott_id      = v.lott_id;
			betData.period       = v.period;
			betData.betting      = v.betting;
			betData.bet_item     = v.bet_item;
			betData.bet_string   = v.bet_string;
			betData.bet_amount   = v.bet_amount;
			betData.eo_money     = v.eo_money;
			data.push(betData);
		})
	}
	
	// 遇到空投注对象，返回
	if(flag == 'false') return;
	// 提交数据为空
	if(data.length == 0){
		layer_msg('温馨提示', '没有选择投注号');
		return;
	}
	// 安全提交限制
	securityPost = false;
	// 提交
	var param    = 'data=' + JSON.stringify(data);
	$.ajax({  
		type:'post',    
	    url: betOrder,  
	    data:param,  
	    cache:false,  
	    dataType:'json',  
	    success:function(res){  
	    	if(res.status == 'success'){
	    		layer_msg('温馨提示', '<span style="color:red">投注成功</span>，您可以在我的账户查看注单详情', 'success');
	    		$('.tag_i_want_chase').eq(0).click();
	    		clear_chase();
			}else{
				layer_msg('温馨提示', '投注失败，请重试', '');
			}
	    	// 释放提交
	    	securityPost = true;
	    },
	    error:function (XMLHttpRequest, textStatus, errorThrown){
	    	// 释放提交
	    	securityPost = true;
	    }
	})
	
}

/**
 * 展示提交内容
 */
function showBet(obj, chase){
	var qihao_str = '第<em class="fill layerIssue">' + resData.lotting.period + '</em>期';
	var group_ind = $('.tag_chase_type li[class="curr"]').index();
	if(chase){
		// 构建追号的期号数信息
		var qiList      = $('.tag_main_chase_preiod[group="' + group_ind + '"]');
		var chase_first = ''
		var chase_end   = '';
		var chase_qis   = 0;
		$.each(qiList, function (i, v){
			if($(v).prop('checked')){
				if(chase_first == ''){
					chase_first = $(v).val();
				}else{
					chase_end   = $(v).val();
				}
				chase_qis++;
			}
		})
		qihao_str = chase_first + '期 至第' + chase_end + '期 共' + chase_qis + '期';
	}
	var playTmp = '';
	var str = '<div id="CheckBetLayer" class="lotteryConfirm"> ';
	str    += '	<ul>';
	str    += '		<li><span>彩种：</span><em class="fill">' + resData.lotteryInfo.title + '</em></li>';
	str    += '		<li><span>期号：</span>' + qihao_str + '</li>';
	str    += '		<li><span>详情：</span>';
	str    += '		<div class="fill textarea">';
	$.each(ready_bet, function (i, v){
		playTmp = v.bet_name.split('-');
		str += '		<p>[' + resData.playItem.mainItem[playTmp[0]].play_name + ',' + resData.playItem.mainItem[playTmp[0]].play[playTmp[1]].name + '] ' + v.bet_string + '<br />';
	});
	str    += '		</div>';
	str    += '	</ul>';
	str += '</div>';
	
	layer.open({
        title: '温馨提示',
        content: str,
        className: 'layui-m-tag-msg',
        btn: ['确定', '取消'],
        yes: function (index){
        	bet_post(obj, chase)
        },
    });
}

/**
 * 清除追号内容
 */
function clear_chase(){
	$('.tag_chase_show_list tbody').html();
	var betting    = {};
	ready_bet      = {};
	get_follow_play_mode(play_follow.follow_name);
//	$('.tag_chase_list tbody').html('' );
	$('.tag_checkList tbody').html('');
	chaseData      = {};
	$('.tag_tongji_zhushu').html('0');
	$('.tag_tongji_amount').html('￥0.00');
	$('.tag_chase_type li').removeClass('curr');
	$('.tag_chase_type li').eq(0).addClass('curr');
}

function clear_betting(){
	var betting    = {};
	ready_bet      = {};
	get_follow_play_mode(play_follow.follow_name);
	$('.tag_checkList tbody').html('' );
}

function re_init(){
	loadLotteryInfo();
	load_init();
	$('.tag_chase_show_list').html('')
	if($('.tag_i_want_chase').eq(1).prop('checked')){
		$('.tag_chase_show_list').eq(chaseData.chaseType).html(chase_main_1($('#tag_set_chase_qishu').val(), $('.tag_all_chase').eq(1).val(), $('#tag_set_chase_beishu').val()));
		
	}
}

/**
 * 获取上一期的开奖情况
 */
function getLastPerOpen(){
	var lastPerRequest = {'operation':'getPerInfo', 'pid':resData.shangqi.id};
	$.ajax({  
		type:'post',    
	    url: getLastData,  
	    data:'data=' + JSON.stringify(lastPerRequest),  
	    cache:false,  
	    dataType:'json',  
	    success:function(res){  
	    	if(res.perInfo.code){
	    		// 清除settimeout
	    		clearTimeout(clear_kj_ready);
	    		// 调用上期开奖
	    		shangqi_kaijiang(res.perInfo.code);
	    	}
	    }
	})
	setTimeout("getLastPerOpen()", 1000*60);
}

/**
 * 填充追号起始期
 */
function setChaseBeginPreiod(){
	if($.isEmptyObject(resData.chasePreiod)) return;
	var str = '';
	$.each(resData.chasePreiod, function (i, v){
		str = '<option value="' + v.id + '">' + v.period + '</option>';
		$('.tag_chase_fanbei').append(str);
	});
}

window.onload = function (){
	load_init();
	get_main_play_mode('');
	get_follow_play_mode('');
	setTimeout("getLastPerOpen()", 1000*60);
}
